package tjs.study.notes.dotest.jdk.thread;

/**
 * Created by Nicky.Tang on 2021/11/15 9:04 下午
 *
 * @since 02.12.10
 */
public class DoTestOfSyn {
    public static void main(String[] args)throws Exception {
       DoTestOfSyn synTest1 = new DoTestOfSyn();
        DoTestOfSyn synTest2 = new DoTestOfSyn();
        new Thread(()->{
            try {
//                synTest1.doa();
                synTest1.dob();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            try {
//                synTest2.doa();
                synTest2.dob();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }

    public static synchronized void doa() throws Exception {
        System.out.println("a static sart");
        Thread.currentThread().sleep(5000);
        System.out.println("a static end");
    }

    public synchronized void dob() throws Exception {
        System.out.println("a  sart" + this.toString());
        Thread.currentThread().sleep(5000);
        System.out.println("a  sart" + this.toString());
    }
}
